package com.yonyou.pmclouds.async;

import com.alibaba.dubbo.config.annotation.Service;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.async.mapper.AsyncInfoMapper;
import com.yonyou.pmclouds.basecom.async.AsyncInvocationInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.UUID;

@Service(interfaceClass = AsyncInvocationInfoMaintain.class, version = ApplicationConsts.APPLICATION_VERSION)
public class AsyncInvocationInfoMaintainImpl implements AsyncInvocationInfoMaintain {
    @Autowired
    private AsyncInfoMapper mapper;

    @Override
    public AsyncInvocationInfo insertInfo(AsyncInvocationInfo info) {
        info.setInvocationId(UUID.randomUUID().toString());
        info.setLastUpdateFlag(UUID.randomUUID().toString());
        mapper.insertInfo(info);
        return info;
    }

    @Override
    public AsyncInvocationInfo updateInfo(AsyncInvocationInfo info) {
        // 这里不加锁、不校验是否是最近日志
        mapper.updateInfo(info);
        return info;
    }

    @Override
    public void deleteInfo(AsyncInvocationInfo info) {
        mapper.deleteInfo(new String[]{info.getInvocationId()});
    }
}
